package com.jxpanda.spring.module.auth.config.properties;

import com.jxpanda.spring.module.auth.endpoint.AuthEndpoint;
import com.jxpanda.spring.module.auth.endpoint.JwkSetEndpoint;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;

@Getter
@Setter
@ConfigurationProperties(prefix = "panda.spring.auth.endpoint")
public class EndpointProperties implements InitializingBean {

    private String oauthToken = AuthEndpoint.DEFAULT_PATH;

    private boolean enableJwkSet = true;

    private String jwkSet = JwkSetEndpoint.DEFAULT_PATH;

    @Override
    public void afterPropertiesSet() {
        if (!oauthToken.contains("{" + AuthEndpoint.REGISTRATION_ID + "}")) {
            throw new IllegalArgumentException("oauth-token配置不正确，路径中必须包含{registrationId}占位符。例如：" + AuthEndpoint.DEFAULT_PATH);
        }
    }
}
